using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            cld_ngaythang.SelectedDate = DateTime.Today;
        }
    }
        private void SaveFileUpLoad()
        {
        string strFileName;
        if (FileUpload1.FileName != "")
            {
            strFileName = Server.MapPath("Hinhanh\\" + FileUpload1.FileName);
            FileUpload1.PostedFile.SaveAs(strFileName);
            }

        }
    public void save()
    {
        string sql = "select*from tb_xahoi";
        SqlConnection mysql = new SqlConnection();
        mysql.ConnectionString = "Data Source=NCTHANH;Initial Catalog=TINTUC;Integrated Security=True";
        SqlDataAdapter da = new SqlDataAdapter(sql, mysql);
        SqlCommandBuilder sqlcon = new SqlCommandBuilder(da);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataRow row = ds.Tables[0].NewRow();
        row[0] = txt_mabantin.Text;
        row[1] = txt_tieude.Text;
        row[2] = txt_noidungtomtat.Text;
        row[3] = txt_noidung.Text;
        row[4] = cld_ngaythang.SelectedDate;
        row[5] = FileUpload1.FileName;
        row[6] = txt_chuthichhinh.Text;
        row[7] = txt_linhvuc.Text;
        ds.Tables[0].Rows.Add(row);
        da.Update(ds);
        SaveFileUpLoad();
    
    }
    protected void bntluu_Click(object sender, EventArgs e)
    {

        if (Page.IsValid)
        {
            save();
        }
    }
}
